package com.event.management.frontend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.event.management.frontend.domain.QuestionnaireAnswer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 问卷答案Mapper
 */
@Mapper
public interface QuestionnaireAnswerMapper extends BaseMapper<QuestionnaireAnswer> {
    
    /**
     * 检查用户是否已提交过该活动的问卷
     * @param userId 用户ID
     * @param eventId 活动ID
     * @param ticketId 电子票ID
     * @return 记录数
     */
    @Select("SELECT COUNT(*) FROM questionnaire_answers WHERE user_id = #{userId} AND event_id = #{eventId} AND ticket_id = #{ticketId} LIMIT 1")
    int checkAnswerExists(@Param("userId") Long userId, @Param("eventId") Long eventId, @Param("ticketId") Long ticketId);
    
    /**
     * 更新电子票的问卷回答状态
     * @param ticketId 电子票ID
     * @return 影响行数
     */
    @Update("UPDATE user_tickets SET questionnaire_answered = 1 WHERE id = #{ticketId}")
    int updateTicketQuestionnaireStatus(@Param("ticketId") Long ticketId);
} 